package com.passioneffect.widgets {
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.utils.getDefinitionByName;
	
	import com.passioneffect.display.Component;
	
	import gs.TweenMax;	

	/**
	 * @author Passion Effect
	 */
	dynamic public class CustomSkin extends MovieClip {
		private var skinClass : String;
		private var target : DisplayObject;
		private var skin : MovieClip;
		private var data : Object;
		private var opened:Boolean;
		private var component:Component;
		public var offset:Number=7;
		public var initObj:Object;
		public var lock:Boolean=false;
		
		public function CustomSkin(target : DisplayObject,skinClass : String,data : Object,component,initObj:Object) {
			this.target = target;
			this.skinClass = skinClass;
			this.data = data;
			this.component=component;
			this.initObj=initObj;
			
			var def = getDefinitionByName(skinClass);
			skin = new def();
			
			skin.onContentData(component,data,target.width/target.scaleX,target.height/target.scaleY,offset);
			initObj.toffsetBottom=-skin.label.height-offset*2;
			
			
		}

		public function open() : void {
			if(lock)return;
			target.parent.addChild(skin);
			skin.alpha=0;
			skin.visible=true;
			TweenMax.to(skin, 0.5, {alpha:1});
		}
		
		private function invisible() : void {
			skin.visible=false;
		}

		public function close() : void {
			TweenMax.to(skin, 0.3, {onComplete:invisible,alpha:0});
		}
	}
}
